package cn.bobohost.crmrbac.web.controller;

import cn.bobohost.crmrbac.pojo.po.Customer;
import cn.bobohost.crmrbac.pojo.query.CustomerQuery;
import cn.bobohost.crmrbac.pojo.query.EchartsQuery;
import cn.bobohost.crmrbac.service.CustomerService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 波波老师
 * @since 2025-05-21
 */
@Controller
@RequestMapping("/customer")
@RequiredArgsConstructor
@Slf4j
public class CustomerController {

    //注入客户service
    private final CustomerService customerService;

    /**
     * 潜在客户管理
     * @param model
     * @param customerQuery
     * @return
     */
    @RequestMapping("/potentialCustomer")
    public String potentialCustomer(Model model, @ModelAttribute("qo") CustomerQuery customerQuery){
        //设置查询所有（不限显示的最大条数）
        customerQuery.setPageSize(0);
        //查询市场专员
//        List<Employee> sellers = employeeService.selectAllSellers();
//        model.addAttribute("sellers",sellers);
        //设置分页显示的最大条数
        customerQuery.setPageSize(2);
        //查询潜在客户信息
        PageInfo<Customer> pageInfo = customerService.selectPotentialCustomerByCondition(customerQuery);
        //传到页面
        model.addAttribute("pageInfo",pageInfo);


//        //查询职业下拉框
//        List<SystemDictionaryItem> jobs = systemDictionaryItemService.selectAllJobs();
//        model.addAttribute("jobs",jobs);
//        //查询来源下拉框
//        List<SystemDictionaryItem> sources = systemDictionaryItemService.selectAllSources();
//        model.addAttribute("sources",sources);
//        //查询跟进方式下拉框
//        List<SystemDictionaryItem> traceTypeIds = systemDictionaryItemService.selectAllTraceTypeIds();
//        model.addAttribute("traceTypeIds",traceTypeIds);
//        //查询跟进结果下拉框
//        List<SystemDictionaryItem> traceResults = systemDictionaryItemService.selectAllTraceResults();
//        model.addAttribute("traceResults",traceResults);
//        //查找移交里面的新营销人员
//        List<Employee> employees = employeeService.selectAllNewSellers();
//        model.addAttribute("employees",employees);
//        //查询跟进类型下拉框
//        List<SystemDictionaryItem> types = systemDictionaryItemService.selectAllTypes();
//        model.addAttribute("types",types);
        //跳转到页面
        return "customer/potentialcustomerlist";
    }

    /**
     * 进入潜在客户报表页面(潜在客户报表的查询)
     */
    @RequestMapping("/toReportsPage")
    public String toReportsPage(Model model,@ModelAttribute("qo") CustomerQuery customerQuery,String keyword,String dateBegin,String dateEnd){
        //设置分页尺寸为0，即查所有
        customerQuery.setPageSize(0);
        PageInfo<EchartsQuery> pageInfo = customerService.getEchartsQueryList(customerQuery,keyword,dateBegin,dateEnd);
        model.addAttribute("pageInfo",pageInfo);
        return "customer/echarts";
    }

    //处理柱状图的ajax数据
    @RequestMapping("/zhuAjax")
    @ResponseBody
    public Map<String,Object> zhuAjax(Integer groupType, String keyword, String dateBegin, String dateEnd){
        return customerService.countCustomerMake(groupType,keyword,dateBegin,dateEnd);
    }


}
